

#import "CYLPlusButtonSubclass.h"
#import "CYLTabBarController.h"

#import "HJTAnimationView.h"
#import "putMyAnsViewController.h"
#import "putMyConsultViewController.h"

@interface CYLPlusButtonSubclass ()<UIActionSheetDelegate> {
    CGFloat _buttonImageHeight;
}

@end

@implementation CYLPlusButtonSubclass

#pragma mark -
#pragma mark - Life Cycle

+ (void)load {
    [super registerSubclass];
}

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self.titleLabel.textAlignment = NSTextAlignmentCenter;
        self.adjustsImageWhenHighlighted = NO;
    }
    return self;
}

//上下结构的 button
- (void)layoutSubviews {
    [super layoutSubviews];
    
    // 控件大小,间距大小
    CGFloat const imageViewEdgeWidth   = self.bounds.size.width;
    CGFloat const imageViewEdgeHeight  = imageViewEdgeWidth;
    CGFloat const centerOfView    = self.bounds.size.width * 0.5;
    CGFloat const labelLineHeight = self.titleLabel.font.lineHeight;
    CGFloat const verticalMarginT = self.bounds.size.height - labelLineHeight - imageViewEdgeWidth;
    CGFloat const verticalMargin  = verticalMarginT / 2;
    
    // imageView 和 titleLabel 中心的 Y 值
    CGFloat const centerOfImageView  = verticalMargin + imageViewEdgeWidth * 0.5;
   // CGFloat const centerOfTitleLabel = imageViewEdgeWidth  + verticalMargin * 2 + labelLineHeight * 0.5 + 5;
    
    //imageView position 位置
    self.imageView.bounds = CGRectMake(0, 0, imageViewEdgeWidth, imageViewEdgeHeight);
    self.imageView.center = CGPointMake(centerOfView, centerOfImageView);
    
}

#pragma mark -
#pragma mark - CYLPlusButtonSubclassing Methods

/*
 *
 Create a custom UIButton with title and add it to the center of our tab bar
 *
 */
+ (instancetype)plusButton {
    CYLPlusButtonSubclass *button = [[CYLPlusButtonSubclass alloc] init];
    UIImage *buttonImage = [UIImage imageNamed:@"Tabadd@2x"];
    [button setImage:buttonImage forState:UIControlStateNormal];

    [button sizeToFit]; 
    [button addTarget:button action:@selector(clickPublish) forControlEvents:UIControlEventTouchUpInside];
    return button;
}


#pragma mark -
#pragma mark - Event Response

- (void)clickPublish {
 
    HJTAnimationView *animationView = [[HJTAnimationView alloc]initWithTitleArray:nil picarray:@[@"answer.png",@"utterance.png"]];
    [animationView selectedWithIndex:^(NSInteger index) {
        if (index==1)
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"jumpVC" object:@(1)];
        }
        else if (index==2)
        {
            [[NSNotificationCenter defaultCenter] postNotificationName:@"jumpVC" object:@(2)];
        }
    }];
    [animationView CLBtnBlock:^(UIButton *btn) {
        
    }];
    [animationView show];
 
}



#pragma mark - CYLPlusButtonSubclassing


+ (CGFloat)multiplerInCenterY {
    return  0.3;
}

@end
